package com.spzx.product.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.log.annotation.Log;
import com.spzx.common.log.enums.BusinessType;
import com.spzx.common.security.annotation.RequiresLogin;
import com.spzx.common.security.annotation.RequiresPermissions;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.product.domain.Brand;
import com.spzx.product.domain.CategoryBrand;
import com.spzx.product.service.ICategoryBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 分类品牌 前端控制器
 * </p>
 *
 * @author lee
 * @since 2024-07-13
 */
@Tag(name = "分类品牌管理")
@RestController
@RequestMapping("/categoryBrand")
@RequiresLogin
public class CategoryBrandController extends BaseController {
    @Autowired
    private ICategoryBrandService categoryBrandService;

    @Operation(summary = "根据分类id获取品牌列表")
    @GetMapping("brandList/{id}")
    public AjaxResult getBrandList(@PathVariable Long id){
        List<Brand> list = categoryBrandService.getBrandList(id);
        return success(list);
    }
    @Operation(summary = "分页查询分类品牌列表")
    @GetMapping("/getBrandList")
    @RequiresPermissions("product:categoryBrand:list")
    public TableDataInfo list(CategoryBrand categoryBrand){
        startPage();
        List<CategoryBrand> list = categoryBrandService.selectCategoryBrandList(categoryBrand);
        return getDataTable(list);
    }

    @Operation(summary = "新增分类品牌")
    @Log(title = "分类品牌", businessType = BusinessType.INSERT)
    @PostMapping
    @RequiresPermissions("product:categoryBrand:add")
    public AjaxResult insert(@Validated @RequestBody CategoryBrand categoryBrand){

        return toAjax(categoryBrandService.insertCategoryBrand(categoryBrand));
    }
    @Operation(summary = "修改分类品牌")
    @Log(title = "分类品牌", businessType = BusinessType.UPDATE)
    @PutMapping
    @RequiresPermissions("product:categoryBrand:edit")
    public AjaxResult update (@Validated @RequestBody CategoryBrand categoryBrand){

        return toAjax(categoryBrandService.updateCategoryBrand(categoryBrand));
    }
    @Operation(summary = "获取分类品牌详细信息")
    @GetMapping("/{id}")
    @RequiresPermissions("product:categoryBrand:query")
    public AjaxResult getDetail (@PathVariable("id") Long id){
        CategoryBrand categoryBrand = categoryBrandService.selectCategoryBrandById(id);
        return success(categoryBrand);
    }


    @Operation(summary = "删除分类品牌")
    @Log(title = "分类品牌", businessType = BusinessType.DELETE)
    @DeleteMapping("{id}")
    @RequiresPermissions("product:categoryBrand:delete")
    public AjaxResult remove (@PathVariable("id")List<Long> ids){
        return toAjax(categoryBrandService.removeByIds(ids));
    }
}
